import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:oktoast/oktoast.dart';
import 'package:starfish_tenement_app/route/route_path.dart';
import 'package:starfish_tenement_app/route/route_utils.dart';
import 'package:starfish_tenement_app/route/routes.dart';

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return OKToast(
        child: ScreenUtilInit(
            designSize: _designSize,
            builder: (context, child) {
              return MaterialApp(
                theme: ThemeData(
                    tabBarTheme: const TabBarTheme(
                        dividerColor: Colors.transparent),
                    useMaterial3: true
                ),
                // 实现全局路由跳转
                navigatorKey: RouteUtils.navigatorKey,
                // 定义的路由
                onGenerateRoute: Routes.generateRoute,
                // 默认打开的页面
                initialRoute: RoutePath.tab,
              );
            }));
  }
}


/// 设计尺寸
Size get _designSize {
  final firstView = WidgetsBinding.instance.platformDispatcher.views.first;
  // 逻辑短边
  final logicalShortestSide = firstView.physicalSize.shortestSide / firstView.devicePixelRatio;
  // 逻辑长边
  final logicalLongestSide = firstView.physicalSize.longestSide / firstView.devicePixelRatio;
  // 缩放比例 designSize越小，元素越大
  const scaleFactor = 1;
  // 缩放后的逻辑短边和长边
  return Size(logicalShortestSide * scaleFactor, logicalLongestSide * scaleFactor);
}